package com.magold.logic.magold;

import org.andengine.engine.handler.IUpdateHandler;

import com.magold.logic.item.ItemBeneficiary.PowerSupports;
import com.magold.skill.BaseSkill;

public class PowerGuard implements IUpdateHandler {
	private float mLossSpeed;
	private BaseSkill mControlSkill;
	private PowerSupports mPowerOwner;
	
	public PowerGuard(float pLossSpeed, BaseSkill pSkill, PowerSupports pPowerOwner) {
		setLossSpeed(pLossSpeed);
		mControlSkill = pSkill;
		mPowerOwner = pPowerOwner;
	}
	
	public void setSkill(BaseSkill pControlSkill) {
		mControlSkill = pControlSkill;
	}
	
	public void setLossSpeed(float pLossSpeed) {
		mLossSpeed = - Math.abs(pLossSpeed);
	}
	
	@Override
	public void onUpdate(float pSecondsElapsed) {
		float rest = mPowerOwner.addPower(mLossSpeed* pSecondsElapsed);
		if (rest <= 0) {
			mControlSkill.stop();
		}
	}

	@Override
	public void reset() {
	}

}
